package com.chapter2;

import lombok.Data;

@Data
public class Student {

    //必选参数
    private final int id;

    private final String name;

    //可选参数
    private int score;

    private int age;

    private int rank;

    public Student (Builder builder){
        this.id=builder.id;
        this.name=builder.name;
        this.score=builder.score;
        this.age=builder.age;
        this.rank=builder.rank;
    }

    public static class Builder{
        //必选参数
        private final int id;

        private final String name;

        //可选参数
        private int score;

        private int age;

        private int rank;


        public Builder(int id,String name){
            this.id=id;
            this.name=name;
        }

        public Builder score(int val){
            this.age=val;
            return this;
        }

        public Builder age(int val){
            this.age=val;
            return this;
        }

        public Builder rank(int val){
            this.rank=val;
            return this;
        }

        public Student builder(){
            Student student=new Student(this);
            return student;
        }

    }

    public static void main(String[] args) {
        Student student=new Builder(1,"小明").age(22).rank(1).builder();
        System.out.println(student.toString());
    }
}
